<html>

	<head>
		<meta charset="UTF-8">
		<title>不支持查看</title>
		<!--标准mui.css-->
		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" href="../../css/mooc.css">
	</head>
	<style>
		body {
			background: white;
		}
		
		.mui-title {
			color: white;
		}
		
		.mui-icon-left-nav {
			color: white;
		}
		
		.mui-icon-download {
			color: white;
			font-size: 30px;
			font-weight: bold;
			width: 40px;
		}
		
		.mui-content {
			background: white;
		}
		
		.mui-bar.mui-bar-tab {
			background: white;
		}
		
		.footbtndiv {
			text-align: center;
			padding-top: 13px;
		}
		
		.footbtnspan {
			padding: 6px 18px 6px 18px;
			border: 1px solid #d5d5d5;
			border-radius: 3px;
			color: #ffb36e;
			font-size: 13px;
		}
	</style>

	<body>
		<header class="mui-bar mui-bar-nav headbar">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<a id="downloadvideo" class="opennoteview mui-icon mui-icon-download mui-pull-right"></a>
			<h1 class="mui-title" id='resnameh1'></h1>
		</header>
		<div class="mui-content">
			<img src="../../images/empty_default.png" style="width:96%;" />
		</div>
		<nav class="mui-bar mui-bar-tab">
			<div class="footbtndiv"><span class="footbtnspan">其他应用打开</span></div>
		</nav>
	</body>
	<script type="text/javascript" src="../../js/mui.min.js"></script>
	<script type="text/javascript" src="../../script/config.js"></script>
	<script type="text/javascript" src="../../js/DMobileFrame_DownLoadUtil.js"></script>
	<script src="../../script/moocpublic.js"></script>
	<script>
		var downloadUtils = require('scripts/Core/DownLoadUtil.js');
		var localStorageManagers = require('script/localStorageManagers.js');
		(function($) {
			//mui初始化
			mui.init({
				swipeBack: true
			});
			//plus初始化
			mui.plusReady(function() {
				var self = plus.webview.currentWebview();
				var respath = self.path;
				document.getElementById('resnameh1').innerHTML = self.attachname;
				//其他应用打开
				mui('.footbtndiv').on('tap', '.footbtnspan', function() {
					respath = downloadUtils.getLocalAbsoluteUrl2(respath); //打开文件需要相对路径
					var suffix = respath.substring(respath.lastIndexOf('.') + 1, respath.length);
					if (respath.indexOf('http:') >= 0) {
						//mui.toast('请先下载到本地');
						plus.runtime.openURL(respath, {}, function(e) {
							plus.nativeUI.alert("无法打开'" + suffix + "'格式的文件,请安装相关应用.");
						});
					} else {
						plus.runtime.openFile(respath, {}, function(e) {
							plus.nativeUI.alert("无法打开'" + suffix + "'格式的文件,请安装相关应用。");
						});
					}
				});
				//下载视频
				mui('header').on('tap', '#downloadvideo', downLoadVideo);
			});
		})(mui);
		//下载视频
		function downLoadVideo() {
			var self = plus.webview.currentWebview();
			var key = buildResKey(2, self.discussid, self.attachid);
			var res = {
				title: self.attachname,
				key: key,
				path: self.path,
				resCatName: '文本',
				courseName: self.discussname,
				catalogName: self.discussname,
				resSize: '1'
			};
			var issave = localStorageManagers.pushDownresourceSessionItem(res);
			//下载在课程页面进行
			if (issave) {
				var parentWebView = plus.webview.getWebviewById("synccourse/courseindex.html");
				parentWebView.evalJS("downloadResource('" + self.path + "')");
				mui.toast("开始下载");
			} else {
				mui.toast("已下载");
			}
		}
	</script>

</html>